<?php

class Application_Model_DbTable_Orders extends Zend_Db_Table_Abstract
{

    protected $_name = 'orders';
    
    public function getOrder($order_no)
    {
    	$order_no = (double)$order_no;
    	$row = $this->fetchRow('order_no = ' . $order_no);
    	if (!$row) {
    		throw new Exception("Could not find row $order_no");
    	}
    	return $row->toArray();
    }

	public function addOrder($order_no, $order_date, $order_status, $order_price, $staff_no, $cust_no)
    {
    	$data = array(
    				'order_no'=>$order_no,
    				'order_date'=>$order_date,
    				'order_status'=>$order_status, 
    				'order_price'=>$order_price,
    				'staff_no'=>$staff_no,
    				'cust_no'=>$cust_no,
    	);
    	$this->insert($data);
    }
    public function deleteOrder($order_no)
    {
    	$this->delete('order_no = '. (double)$order_no);
    }
    public function cancelOrder($order_no)
    {
    	$cancel = 'C';
    	$data = array(
        		'order_status'=> $cancel
    	 
    	);
    	$this->update($data, 'order_no = ' . (double)$order_no );
    	
    }
   	public function updateOrder($order_no, $total_price)
   	{
   		$data = array(
   			'order_price' => $total_price
   		);
   		$this->update($data, 'order_no = '. (double)$order_no);
   	}
    public function itemdelOrder($order_no, $result_price)
    {
    	$data = array(
    			'order_price'=> $result_price
    	);
    	$this->update($data, 'order_no = '.(double)$order_no);
    }
    public function confOrder($order_no)
    {
    	$data = array(
    			'order_conf'=> 'Y'
    	);
    	$this->update($data, 'order_no = '.(double)$order_no);
    }
}

